#include "Timer.h"
#include "Thread.h"

namespace {

class Task : public Thread {
public:
  Task(void *obj, void (*callback)(void*), int seconds) {
    this->obj = obj;
    this->callback = callback;
    this->seconds = seconds;
  }
  
protected:
  virtual void run() {
    sleep(seconds);
    callback(obj);
    delete this;
  }
  
private:
  void *obj;
  void (*callback)(void*);
  int seconds;
};

}
namespace Timer {

void schedule(void *obj, void (*callback)(void*), int seconds) {
  Task *task = new Task(obj, callback, seconds);
  task->start();
}

}
